/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb.warehouse;

import ejb.system.AbstractFacade;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author ciummo
 */
@Stateless
public class OrdineFacade extends AbstractFacade<Ordine> implements OrdineFacadeRemote {
    @PersistenceContext(unitName = "DGestEJBSeverPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public OrdineFacade() {
        super(Ordine.class);
    }
    
    
    public Ordine findOrdineById (int idOrder){
        
        Ordine o = null;
        
        try {
            String sql = "SELECT o FROM Ordine o WHERE o.idOrdine = :idOrdine";
            Query query = em.createQuery(sql);
            query.setParameter("idOrdine", idOrder);
            
            o = ((Ordine) query.getResultList().get(0));
            }
            catch (Exception ex) {
                return o;
            }
        return o;
    }   
    
}
